package com.wkg;

public class Test_102 {

    public static void main(String[] args) throws InterruptedException {
        IncreaseCount increaseCount = new IncreaseCount();
        Thread th1 = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                increaseCount.increase1();
            }
        });
        Thread th2 = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                increaseCount.increase1();
            }
        });

        th1.start();
        th2.start();
        th1.join();
        th2.join();
        System.out.println(increaseCount.count);
    }

}


class IncreaseCount {
    int count = 0;
    Object object = new Object();

    public void increase1() {
        synchronized (IncreaseCount.class) {
            count++;
        }
    }

    public void increase2() {
        synchronized (IncreaseCount.class) {
            count++;
        }
    }

}